﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using Assist;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKArch.Ramp.Utils;
using YJKArch.Utils;
using YJKRGeometry;

namespace YJKArch.Ramp
{
	public class DrawingKit
	{
		public DrawingKit(ExternalCommandData cmdData)
		{
			this.m_uiApp = cmdData.Application;
			this.m_app = this.m_uiApp.Application;
			this.m_uiDoc = this.m_uiApp.ActiveUIDocument;
			this.m_doc = this.m_uiDoc.Document;
			this.m_lstAxisId = new List<ElementId>();
		}

		public void CreateProfileCurves(List<SegmentData> lstSegmentData, double dMinRadius, ref List<CurveInfo> lstCurveInfo, ref List<TextNoteInfo> lstTextNoteInfo)
		{
			try
			{
				double num = double.MaxValue;
				List<double> list = new List<double>();
				List<double> list2 = new List<double>();
				List<Curve> list3 = new List<Curve>();
				int i = 0;
				while (i < lstSegmentData.Count)
				{
					if (i <= 0 || i >= lstSegmentData.Count - 1 || !CreateRampForm.IsTransitionSegment(lstSegmentData[i - 1], lstSegmentData[i], lstSegmentData[i + 1]))
					{
						goto IL_8E;
					}
					XYZ xyz = null;
					lstSegmentData[i].Center(ref xyz);
					if (!YJKArch.Utils.Geometry.LessThan(Common.FeetToMM(xyz.DistanceTo(lstSegmentData[i - 1].EndPoint)), dMinRadius))
					{
						goto IL_8E;
					}
					IL_F2:
					i++;
					continue;
					IL_8E:
					double num2 = AssistFunc.mmToFeet(lstSegmentData[i].LeftWidth);
					double num3 = AssistFunc.mmToFeet(lstSegmentData[i].RightWidth);
					list.Add(num2);
					list2.Add(num3);
					list3.Add(lstSegmentData[i].GetCurve(this.m_app));
					if (YJKArch.Utils.Geometry.LessThan(num2 + num3, num))
					{
						num = num2 + num3;
						goto IL_F2;
					}
					goto IL_F2;
				}
				List<ThreeLine> list4 = new DoubleLineCliper(this.m_app).CalculaterDoubleLine(list3, list, list2);
				if (list4.Count >= 1)
				{
					for (i = 0; i < list4.Count; i++)
					{
						ThreeLine threeLine = list4[i];
						foreach (YJKArch.Utils.EdgeInfo edgeInfo in threeLine.GetLoop())
						{
							if (!edgeInfo.IsPoint)
							{
								lstCurveInfo.Add(new CurveInfo(edgeInfo.ConvertTo(this.m_app), PenColor.PC_Gray, 2f));
							}
						}
						List<CurveInfo> collection = this.CreateArrows(threeLine.CenterLine, threeLine.LeftWidth() / 2.0, threeLine.RightWidth() / 2.0);
						lstCurveInfo.AddRange(collection);
						Curve curve = threeLine.CenterLine.ConvertTo(this.m_app);
						XYZ center;
						if (curve.GetType() == typeof(Line))
						{
							center = YJKArch.Utils.Geometry.CalculatMidPoint(curve as Line);
						}
						else
						{
							center = YJKArch.Utils.Geometry.CalculatMidPoint(curve as Arc);
						}
						string text = (i + 1).ToString();
						TextNoteInfo item = new TextNoteInfo(text, PenColor.PC_Black, num / 3.0, center, num * 0.6 * (double)text.Length, num * 0.6);
						lstTextNoteInfo.Add(item);
					}
				}
			}
			catch (Exception)
			{
			}
		}

		public void CreateSecotionCurves(List<SegmentData> lstSegmentData, ref List<CurveInfo> lstCurveInfo, ref List<TextNoteInfo> lstTextNoteInfo)
		{
			try
			{
				double num = 0.0;
				foreach (SegmentData segmentData in lstSegmentData)
				{
					num += segmentData.Length();
				}
				float num2 = 2f;
				double num3 = num / 200.0;
				double num4 = 0.0;
				for (int i = 0; i < lstSegmentData.Count; i++)
				{
					SegmentData segmentData2 = lstSegmentData[i];
					double num5 = segmentData2.Length();
					double num6 = AssistFunc.mmToFeet(segmentData2.StartElevation);
					double num7 = AssistFunc.mmToFeet(segmentData2.EndElevation);
					XYZ xyz = new XYZ(num4, num6, 0.0);
					XYZ xyz2 = new XYZ(num4 + num5, num7, 0.0);
					Curve curve;
					if (segmentData2.VertArcRadius > 0.01)
					{
						double dVertRadius = AssistFunc.mmToFeet(segmentData2.VertArcRadius);
						curve = this.SegmentVertArc(xyz, xyz2, dVertRadius);
						if (curve == null)
						{
							curve = YJKLineEx.YJKGetBound(xyz, xyz2);
						}
					}
					else
					{
						curve = YJKLineEx.YJKGetBound(xyz, xyz2);
					}
					lstCurveInfo.Add(new CurveInfo(curve, PenColor.PC_Gray, num2));
					XYZ xyz3 = curve.Evaluate(0.5, true);
					string text = (i + 1).ToString();
					TextNoteInfo item = new TextNoteInfo(text, PenColor.PC_Black, num3 * 4.0, xyz3, num3 * 6.0 * (double)text.Length, num3 * 6.0);
					lstTextNoteInfo.Add(item);
					if (i > 0)
					{
						XYZ xyz4 = xyz + XYZ.BasisX * num3;
						XYZ radianPnt = xyz + XYZ.BasisY * num3;
						XYZ xyz5 = xyz + -XYZ.BasisX * num3;
						XYZ radianPnt2 = xyz + -XYZ.BasisY * num3;
						Arc curve2 = this.m_app.CreatYJKArc(xyz4, xyz5, radianPnt);
						lstCurveInfo.Add(new CurveInfo(curve2, PenColor.PC_Black, num2 * 2f));
						Arc curve3 = this.m_app.CreatYJKArc(xyz5, xyz4, radianPnt2);
						lstCurveInfo.Add(new CurveInfo(curve3, PenColor.PC_Black, num2 * 2f));
					}
					if (YJKArch.Utils.Geometry.Lessthan_Or_Equal(num4, num / 2.0) && YJKArch.Utils.Geometry.Lessthan_Or_Equal(num / 2.0, num4 + num5))
					{
						double num8 = num / 20.0;
						XYZ tangentAtParameter = this.GetTangentAtParameter(curve, 0.5);
						XYZ xyz6 = YJKArch.Utils.Geometry.RotateTo(-tangentAtParameter, 0.52359877559829882, XYZ.BasisZ) * num8;
						XYZ xyz7 = YJKArch.Utils.Geometry.RotateTo(-tangentAtParameter, -0.52359877559829882, XYZ.BasisZ) * num8;
						Line curve4 = YJKLineEx.YJKGetBound(xyz3, xyz3 + xyz7);
						lstCurveInfo.Add(new CurveInfo(curve4, PenColor.PC_Black, num2));
						Line curve5 = YJKLineEx.YJKGetBound(xyz3, xyz3 + xyz6);
						lstCurveInfo.Add(new CurveInfo(curve5, PenColor.PC_Black, num2));
					}
					num4 += num5;
				}
			}
			catch (Exception)
			{
			}
		}

		public List<ElementId> CreateExpandedView(Dictionary<Level, List<SegmentData>> lstAllSegmentData, XYZ ptOrigin, DimensionType dimType, TextNoteType textType, FloorType floorType, int nSlopeType, bool bDimLeft, bool bDimTop)
		{
			this.m_lstNewElemId = new List<ElementId>();
			if (lstAllSegmentData.Count < 1)
			{
				return this.m_lstNewElemId;
			}
			this.m_dimType = dimType;
			this.m_textType = textType;
			this.m_floorType = floorType;
			this.m_nSlopeType = nSlopeType;
			this.m_lstAllSegmentData = lstAllSegmentData;
			Transaction transaction = new Transaction(this.m_doc);
			transaction.Start("DrawExpandedView");
			try
			{
				this.CreateRampsSection(ptOrigin);
				this.CreateIntersectAxis(ptOrigin);
				this.CreateRampsDimension(ptOrigin, bDimLeft, bDimTop);
				this.CreateIntersectBeam(ptOrigin);
				this.CreateLevelLines(ptOrigin);
				transaction.Commit();
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				transaction.RollBack();
			}
			return this.m_lstNewElemId;
		}

		private void CreateRampsSection(XYZ ptOrigin)
		{
			AssistFunc.mmToFeet(500.0);
			AssistFunc.mmToFeet(500.0);
			double elevation = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Key.Elevation;
			XYZ xyz = ptOrigin + new XYZ(0.0, -elevation, 0.0);
			double num = this.CalRampVertThick();
			foreach (KeyValuePair<Level, List<SegmentData>> keyValuePair in this.m_lstAllSegmentData)
			{
				Level key = keyValuePair.Key;
				List<SegmentData> value = keyValuePair.Value;
				List<Curve> lstTopCurve = new List<Curve>();
				List<Curve> lstBottomCurve = new List<Curve>();
				bool bDimRadius = true;
				bool bDimFloorThick = true;
				XYZ xyz2 = xyz + new XYZ(0.0, key.Elevation, 0.0);
				for (int i = 0; i < value.Count; i++)
				{
					SegmentData segmentData = value[i];
					double num2 = segmentData.Length();
					double num3 = AssistFunc.mmToFeet(segmentData.EndElevation - segmentData.StartElevation);
					XYZ xyz3 = new XYZ(xyz2.X, xyz2.Y, 0.0);
					XYZ xyz4 = xyz3 + new XYZ(num2, num3, 0.0);
					XYZ xyz5 = xyz3 + new XYZ(0.0, -num, 0.0);
					XYZ xyz6 = xyz4 + new XYZ(0.0, -num, 0.0);
					if (segmentData.VertArcRadius > 0.1)
					{
						if (!this.CreateArcRampSeg(segmentData, xyz3, xyz4, xyz5, xyz6, bDimRadius, lstTopCurve, lstBottomCurve))
						{
							this.CreateLineRampSeg(segmentData, xyz3, xyz4, xyz5, xyz6, bDimFloorThick, lstTopCurve, lstBottomCurve);
							bDimFloorThick = false;
						}
						else
						{
							bDimRadius = false;
						}
					}
					else
					{
						this.CreateLineRampSeg(segmentData, xyz3, xyz4, xyz5, xyz6, bDimFloorThick, lstTopCurve, lstBottomCurve);
						bDimFloorThick = false;
					}
					if (i == 0)
					{
						Line line = YJKLineEx.YJKGetBound(xyz5, xyz3);
						DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
						this.m_lstNewElemId.Add(detailCurve.Id);
					}
					else if (i == value.Count - 1)
					{
						Line line2 = YJKLineEx.YJKGetBound(xyz4, xyz6);
						DetailCurve detailCurve2 = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line2);
						this.m_lstNewElemId.Add(detailCurve2.Id);
					}
					xyz2 = xyz4;
				}
				this.m_lstNewElemId.AddRange(this.DrawFloorFill(lstTopCurve, lstBottomCurve));
			}
		}

		private void CreateRampsDimension(XYZ ptOrigin, bool bDimLeft, bool bDimTop)
		{
			double segmentMinElevation = this.GetSegmentMinElevation();
			double segmentMaxElevation = this.GetSegmentMaxElevation();
			double num = AssistFunc.mmToFeet(500.0);
			if (bDimLeft)
			{
				List<XYZ> elevDimPoints = this.GetElevDimPoints(ptOrigin, AssistFunc.mmToFeet(500.0));
				if (elevDimPoints.Count > 1)
				{
					XYZ xyz = new XYZ(-num, 0.0, 0.0);
					XYZ ptLeader = elevDimPoints[0] + xyz;
					this.m_lstNewElemId.AddRange(this.DrawDimensions(elevDimPoints, ptLeader));
					if (elevDimPoints.Count > 2)
					{
						XYZ xyz2 = elevDimPoints[0];
						XYZ ptDim = elevDimPoints[elevDimPoints.Count - 1];
						XYZ ptLeader2 = xyz2 + 2.5 * xyz;
						this.m_lstNewElemId.AddRange(this.DrawDimension(xyz2, ptDim, ptLeader2));
					}
				}
			}
			if (bDimTop)
			{
				List<SegmentData> value = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Value;
				double num2 = AssistFunc.mmToFeet(segmentMaxElevation - segmentMinElevation + 800.0);
				double num3 = 0.0;
				for (int i = 0; i < value.Count; i++)
				{
					SegmentData segmentData = value[i];
					num3 += AssistFunc.mmToFeet(segmentData.EndElevation - segmentData.StartElevation);
				}
				if (num3 < -0.001)
				{
					num2 += num3;
				}
				XYZ xyz3 = new XYZ(0.0, num2, 0.0);
				XYZ xyz4 = ptOrigin;
				List<XYZ> list = new List<XYZ>();
				for (int j = 0; j < value.Count; j++)
				{
					XYZ xyz5 = new XYZ(value[j].Length(), 0.0, 0.0);
					XYZ xyz6 = xyz4 + xyz3;
					XYZ item = xyz6 + xyz5;
					list.Add(xyz6);
					list.Add(item);
					xyz4 += xyz5;
				}
				List<XYZ> list2 = this.MoveSamePoint(list);
				if (list2.Count > 1)
				{
					XYZ xyz7 = new XYZ(0.0, num, 0.0);
					XYZ xyz8 = list2[0] + xyz7;
					ReferenceArray referenceArray = this.CreateDimRefs(list2, xyz8);
					foreach (XYZ xyz9 in list2)
					{
						double minDist = this.GetMinDist(xyz9, list2);
						Reference nearAxisRef = this.GetNearAxisRef(xyz9, list2, minDist);
						if (nearAxisRef != null && !this.IsHasReference(referenceArray, nearAxisRef))
						{
							referenceArray.Append(nearAxisRef);
						}
					}
					XYZ xyz10 = list2[1] - list2[0];
					XYZ xyz11 = xyz8 + 100.0 * xyz10;
					Line line = Line.CreateBound(xyz8, xyz11);
					Dimension dimension = this.m_doc.Create.NewDimension(this.m_doc.ActiveView, line, referenceArray, this.m_dimType);
					if (dimension != null)
					{
						RevitDimensionExtension.ResetDimTextPos(dimension);
						this.m_lstNewElemId.Add(dimension.Id);
					}
					if (value.Count > 1)
					{
						XYZ xyz12 = ptOrigin + xyz3;
						XYZ ptDim2 = xyz4 + xyz3;
						XYZ ptLeader3 = xyz12 + 2.5 * xyz7;
						this.m_lstNewElemId.AddRange(this.DrawDimension(xyz12, ptDim2, ptLeader3));
					}
				}
			}
		}

		private void CreateIntersectAxis(XYZ ptOrigin)
		{
			double segmentMinElevation = this.GetSegmentMinElevation();
			double num = AssistFunc.mmToFeet(this.GetSegmentMaxElevation() - segmentMinElevation + 3000.0);
			double num2 = AssistFunc.mmToFeet(-1500.0);
			List<SegmentData> value = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Value;
			double num3 = 0.0;
			for (int i = 0; i < value.Count; i++)
			{
				SegmentData segmentData = value[i];
				num3 += AssistFunc.mmToFeet(segmentData.EndElevation - segmentData.StartElevation);
			}
			if (num3 < -0.001)
			{
				num += num3;
				num2 += num3;
			}
			GraphicsStyle lineStyle = this.LoadLineStyle("<中心线>");
			List<Grid> lstAllGrid = (from g in new FilteredElementCollector(this.m_doc).OfClass(typeof(Grid))
			select g as Grid).ToList<Grid>();
			List<ElementId> list = new List<ElementId>();
			XYZ xyz = ptOrigin + new XYZ(0.0, num2, 0.0);
			XYZ xyz2 = ptOrigin + new XYZ(0.0, num, 0.0);
			List<XYZ> list2 = new List<XYZ>();
			for (int j = 0; j < value.Count; j++)
			{
				SegmentData segmentData2 = value[j];
				Curve curve = segmentData2.GetCurve(this.m_doc.Application);
				foreach (KeyValuePair<XYZ, Grid> keyValuePair in this.GetIntersecGrids(lstAllGrid, curve))
				{
					Grid value2 = keyValuePair.Value;
					double curveLengthAtPoint = this.GetCurveLengthAtPoint(curve, keyValuePair.Key);
					XYZ xyz3 = xyz2 + new XYZ(curveLengthAtPoint, 0.0, 0.0);
					XYZ ptEnd = xyz + new XYZ(curveLengthAtPoint, 0.0, 0.0);
					if (!this.IsContainsPoint(list2, xyz3))
					{
						list2.Add(xyz3);
						list.AddRange(this.DrawAxis(xyz3, ptEnd, lineStyle, value2.Name));
					}
				}
				xyz += new XYZ(segmentData2.Length(), 0.0, 0.0);
				xyz2 += new XYZ(segmentData2.Length(), 0.0, 0.0);
			}
			ReferenceArray referenceArray = new ReferenceArray();
			foreach (ElementId elementId in list)
			{
				Element element = this.m_doc.GetElement(elementId);
				if (element is DetailLine)
				{
					DetailLine detailLine = element as DetailLine;
					referenceArray.Append(detailLine.GeometryCurve.Reference);
				}
			}
			if (referenceArray.Size > 2)
			{
				double num4 = AssistFunc.mmToFeet(-1000.0);
				if (num3 < 0.01)
				{
					num4 += num3;
				}
				XYZ xyz4 = ptOrigin + new XYZ(0.0, num4, 0.0);
				XYZ endPoint = xyz4 + new XYZ(100.0, 0.0, 0.0);
				Line line = YJKLineEx.YJKGetBound(xyz4, endPoint);
				Dimension dimension = this.m_doc.Create.NewDimension(this.m_doc.ActiveView, line, referenceArray, this.m_dimType);
				this.m_lstNewElemId.Add(dimension.Id);
			}
			this.m_lstNewElemId.AddRange(list);
		}

		private void CreateIntersectBeam(XYZ ptOrigin)
		{
			double floorThick = this.GetFloorThick(this.m_floorType);
			double num = this.CalRampVertThick();
			double elevation = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Key.Elevation;
			List<FamilyInstance> allBeams = this.GetAllBeams();
			XYZ xyz = ptOrigin + new XYZ(0.0, -elevation, 0.0);
			foreach (KeyValuePair<Level, List<SegmentData>> keyValuePair in this.m_lstAllSegmentData)
			{
				Level key = keyValuePair.Key;
				List<SegmentData> value = keyValuePair.Value;
				XYZ ptFirstSegmentBottom = xyz + new XYZ(0.0, key.Elevation - num, 0.0);
				this.CreateLevelInterBeam(ptFirstSegmentBottom, floorThick, value, allBeams);
			}
		}

		private void CreateLevelInterBeam(XYZ ptFirstSegmentBottom, double dRampThick, List<SegmentData> lstSegmentData, List<FamilyInstance> lstAllBeam)
		{
			XYZ xyz = ptFirstSegmentBottom;
			foreach (SegmentData segmentData in lstSegmentData)
			{
				double num = AssistFunc.mmToFeet(segmentData.StartElevation);
				double num2 = AssistFunc.mmToFeet(segmentData.EndElevation);
				double num3 = num2 - num;
				Curve curve = segmentData.GetCurve(this.m_doc.Application);
				foreach (KeyValuePair<XYZ, FamilyInstance> keyValuePair in this.GetIntersecBeams(lstAllBeam, curve, num, num2, dRampThick))
				{
					FamilyInstance value = keyValuePair.Value;
					double num4 = this.GetCurveLengthAtPoint(curve, keyValuePair.Key) / curve.Length;
					double num5 = segmentData.Length() * num4;
					double num6 = num3 * num4;
					XYZ ptSegmentBottom = new XYZ(xyz.X + num5, xyz.Y + num6, 0.0);
					this.DrawBeamSection(ptSegmentBottom, value);
				}
				xyz += new XYZ(segmentData.Length(), num3, 0.0);
			}
		}

		private void CreateLevelLines(XYZ ptOrigin)
		{
			double num = AssistFunc.mmToFeet(this.GetSegmentMinElevation());
			double num2 = AssistFunc.mmToFeet(this.GetSegmentMaxElevation());
			List<Level> list = new List<Level>();
			foreach (Level level in this.GetAllLevel())
			{
				if (level.Elevation - num >= -0.001 && level.Elevation - num2 <= 1.0)
				{
					list.Add(level);
				}
			}
			list.Sort((Level l1, Level l2) => l1.Elevation.CompareTo(l2.Elevation));
			List<SegmentData> value = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Value;
			double num3;
			if (list.Count > 1)
			{
				num3 = list[1].Elevation - list[0].Elevation;
			}
			else
			{
				num3 = value.Last<SegmentData>().EndElevation - value.First<SegmentData>().StartElevation;
			}
			XYZ xyz = ptOrigin;
			if (value[0].EndElevation < value[0].StartElevation)
			{
				xyz -= new XYZ(0.0, num3, 0.0);
			}
			double num4 = AssistFunc.mmToFeet(2800.0);
			for (int i = 0; i < list.Count; i++)
			{
				XYZ ptPosition = new XYZ(xyz.X - num4, xyz.Y, 0.0);
				this.m_lstNewElemId.AddRange(this.DrawElevation(ptPosition, list[i], false));
				if (i < list.Count - 1)
				{
					double num5 = list[i + 1].Elevation - list[i].Elevation;
					xyz += new XYZ(0.0, num5, 0.0);
				}
			}
		}

		private void CreateLineRampSeg(SegmentData segment, XYZ ptTopStart, XYZ ptTopEnd, XYZ ptBottomStart, XYZ ptBottomEnd, bool bDimFloorThick, List<Curve> lstTopCurve, List<Curve> lstBottomCurve)
		{
			Line line = YJKLineEx.YJKGetBound(ptTopStart, ptTopEnd);
			DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
			this.m_lstNewElemId.Add(detailCurve.Id);
			lstTopCurve.Add(line);
			Line line2 = YJKLineEx.YJKGetBound(ptBottomStart, ptBottomEnd);
			DetailCurve detailCurve2 = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line2);
			this.m_lstNewElemId.Add(detailCurve2.Id);
			lstBottomCurve.Add(line2);
			this.m_lstNewElemId.AddRange(this.DrawGradient(ptTopStart, ptTopEnd));
			this.m_lstNewElemId.AddRange(this.DrawElevation(ptTopEnd, segment.EndElevation, true));
			if (bDimFloorThick)
			{
				XYZ xyz = ptTopStart + (ptTopEnd - ptTopStart) / 2.0;
				XYZ xyzpoint = line.Project(xyz).XYZPoint;
				XYZ xyzpoint2 = line2.Project(xyz).XYZPoint;
				Line line3 = YJKLineEx.YJKGetBound(xyzpoint, xyzpoint2);
				ReferenceArray referenceArray = new ReferenceArray();
				referenceArray.Append(detailCurve.GeometryCurve.Reference);
				referenceArray.Append(detailCurve2.GeometryCurve.Reference);
				Dimension dimension = this.m_doc.Create.NewDimension(this.m_doc.ActiveView, line3, referenceArray, this.m_dimType);
				if (dimension != null)
				{
					RevitDimensionExtension.ResetDimTextPos(dimension);
					this.m_lstNewElemId.Add(dimension.Id);
				}
			}
		}

		private bool CreateArcRampSeg(SegmentData segment, XYZ ptTopStart, XYZ ptTopEnd, XYZ ptBottomStart, XYZ ptBottomEnd, bool bDimRadius, List<Curve> lstTopCurve, List<Curve> lstBottomCurve)
		{
			double dVertRadius = AssistFunc.mmToFeet(segment.VertArcRadius);
			Arc arc = this.SegmentVertArc(ptTopStart, ptTopEnd, dVertRadius);
			Line line = YJKLineEx.YJKGetBound(ptBottomStart, ptBottomEnd);
			if (arc == null)
			{
				return false;
			}
			DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, arc);
			this.m_lstNewElemId.Add(detailCurve.Id);
			lstTopCurve.Add(arc);
			DetailCurve detailCurve2 = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
			this.m_lstNewElemId.Add(detailCurve2.Id);
			lstBottomCurve.Add(line);
			this.m_lstNewElemId.AddRange(this.DrawElevation(ptTopEnd, segment.EndElevation, true));
			if (bDimRadius)
			{
				this.m_lstNewElemId.AddRange(this.DrawRadiusDim(arc));
			}
			return true;
		}

		private Arc SegmentVertArc(XYZ ptStart, XYZ ptEnd, double dVertRadius)
		{
			Curve curve = Arc.Create(ptStart, dVertRadius, 0.0, Math.PI*2, XYZ.BasisX, XYZ.BasisY);
			Arc arc = Arc.Create(ptEnd, dVertRadius, 0.0, Math.PI*2, XYZ.BasisX, XYZ.BasisY);
			IntersectionResultArray intersectionResultArray = null;
			curve.Intersect(arc, out intersectionResultArray);
			if (intersectionResultArray == null || intersectionResultArray.Size < 2)
			{
				return null;
			}
			XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
			XYZ xyzpoint2 = intersectionResultArray.get_Item(1).XYZPoint;
			XYZ xyz = (xyzpoint.Y > xyzpoint2.Y) ? xyzpoint : xyzpoint2;
			XYZ xyz2 = (ptStart + (ptEnd - ptStart) / 2.0 - xyz).Normalize();
			XYZ xyz3 = xyz + xyz2 * dVertRadius;
			return Arc.Create(ptStart, ptEnd, xyz3);
		}

		private List<XYZ> GetElevDimPoints(XYZ ptOrigin, double dOffset)
		{
			double num = AssistFunc.mmToFeet(this.GetSegmentMinElevation());
			double num2 = AssistFunc.mmToFeet(this.GetSegmentMaxElevation());
			List<Level> list = new List<Level>();
			foreach (Level level in this.GetAllLevel())
			{
				if (level.Elevation - num >= -0.001 && level.Elevation - num2 <= 1.0)
				{
					list.Add(level);
				}
			}
			list.Sort((Level l1, Level l2) => l1.Elevation.CompareTo(l2.Elevation));
			List<SegmentData> value = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Value;
			double num3;
			if (list.Count > 1)
			{
				num3 = list[1].Elevation - list[0].Elevation;
			}
			else
			{
				num3 = value.Last<SegmentData>().EndElevation - value.First<SegmentData>().StartElevation;
			}
			XYZ xyz = ptOrigin;
			if (value[0].EndElevation < value[0].StartElevation)
			{
				xyz -= new XYZ(0.0, num3, 0.0);
			}
			List<XYZ> list2 = new List<XYZ>();
			for (int i = 0; i < list.Count; i++)
			{
				XYZ item = new XYZ(xyz.X - dOffset, xyz.Y, 0.0);
				list2.Add(item);
				if (i < list.Count - 1)
				{
					double num4 = list[i + 1].Elevation - list[i].Elevation;
					xyz += new XYZ(0.0, num4, 0.0);
				}
			}
			return list2;
		}

		private void DrawBeamSection(XYZ ptSegmentBottom, FamilyInstance beam)
		{
			List<ElementId> list = this.FindRampBottomLine(ptSegmentBottom);
			if (list.Count < 1)
			{
				return;
			}
			double num = 0.0;
			double num2 = 0.0;
			this.GetBeamSize(beam, ref num, ref num2);
			if (num == 0.0 || num2 == 0.0)
			{
				return;
			}
			XYZ xyz = new XYZ(0.5 * num, 0.0, 0.0);
			XYZ xyz2 = ptSegmentBottom + new XYZ(0.0, -num2, 0.0);
			XYZ xyz3 = xyz2 - xyz;
			XYZ xyz4 = xyz2 + xyz;
			XYZ xyz5 = ptSegmentBottom - xyz;
			XYZ xyz6 = ptSegmentBottom + xyz;
			this.BreakRampBottomLine(list, num, xyz3, ref xyz5);
			this.BreakRampBottomLine(list, num, xyz4, ref xyz6);
			this.m_lstNewElemId.Add(this.CreateLine(xyz3, xyz5));
			this.m_lstNewElemId.Add(this.CreateLine(xyz4, xyz6));
			this.m_lstNewElemId.Add(this.CreateLine(xyz3, xyz4));
			Parameter parameter = beam.GetParameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
			if (parameter != null)
			{
				string text = parameter.AsValueString();
				if (string.IsNullOrEmpty(text))
				{
					text = "无";
				}
				ElementId fillRegionTypeId = this.GetFillRegionTypeId(text);
				FilledRegion filledRegion = this.FindNearSegmentRegion(ptSegmentBottom);
				if (filledRegion != null && fillRegionTypeId == filledRegion.GetTypeId())
				{
					xyz5 += XYZ.BasisY * AssistFunc.mmToFeet(5.0);
					xyz6 += XYZ.BasisY * AssistFunc.mmToFeet(5.0);
					CurveLoop curveLoop = new CurveLoop();
					curveLoop.Append(YJKLineEx.YJKGetBound(xyz5, xyz3));
					curveLoop.Append(YJKLineEx.YJKGetBound(xyz3, xyz4));
					curveLoop.Append(YJKLineEx.YJKGetBound(xyz4, xyz6));
					List<CurveLoop> lstCurveLoop = filledRegion.GetBoundaries().ToList<CurveLoop>();
					List<CurveLoop> list2 = this.MergeCurveLoop(lstCurveLoop, curveLoop);
					FilledRegion filledRegion2 = FilledRegion.Create(this.m_doc, fillRegionTypeId, this.m_doc.ActiveView.Id, list2);
					if (filledRegion2 != null)
					{
						this.m_lstNewElemId.Remove(filledRegion.Id);
						this.m_lstNewElemId.Add(filledRegion2.Id);
						this.m_doc.DeleteElement(filledRegion);
						return;
					}
				}
				else
				{
					ElementId elementId = this.DrawFilledRegin(new List<XYZ>
					{
						xyz3,
						xyz4,
						xyz6,
						xyz5
					}, fillRegionTypeId);
					if (elementId != null)
					{
						this.m_lstNewElemId.Add(elementId);
					}
				}
			}
		}

		private List<CurveLoop> MergeCurveLoop(List<CurveLoop> lstCurveLoop, CurveLoop curveLoop)
		{
			List<Curve> list = new List<Curve>();
			foreach (CurveLoop loop in lstCurveLoop)
			{
				list.AddRange(this.GetCurveLoopCurves(loop));
			}
			list.AddRange(this.GetCurveLoopCurves(curveLoop));
			CurveLoop curveLoop2 = new CurveLoop();
			foreach (Curve curve in this.GetOuterLoop(list))
			{
				curveLoop2.Append(curve);
			}
			return new List<CurveLoop>
			{
				curveLoop2
			};
		}

		private List<Curve> GetCurveLoopCurves(CurveLoop loop)
		{
			List<Curve> list = new List<Curve>();
			CurveLoopIterator curveLoopIterator = loop.GetCurveLoopIterator();
			while (curveLoopIterator.MoveNext())
			{
				Curve item = curveLoopIterator.Current;
				list.Add(item);
			}
			return list;
		}

		private List<Curve> GetOuterLoop(List<Curve> lstCurve)
		{
			List<Curve> lstCurve2 = this.SplitCurves(lstCurve);
			this.RemoveRepeatCurves(lstCurve2);
			List<DrawingKit.RichPoint> list = this.ConstructRichPoint(lstCurve2);
			this.DeleteSingleEdgePoint(ref list);
			list.Sort((DrawingKit.RichPoint p1, DrawingKit.RichPoint p2) => p1.m_point.X.CompareTo(p2.m_point.X));
			return this.GetLongestPathAreas(list);
		}

		private List<Curve> SplitCurves(List<Curve> lstCurve)
		{
			List<Curve> list = new List<Curve>();
			list.AddRange(lstCurve);
			for (int i = 0; i < list.Count; i++)
			{
				for (int j = i + 1; j < list.Count; j++)
				{
					IntersectionResultArray intersectionResultArray = null;
					list[i].Intersect(list[j], out intersectionResultArray);
					if (intersectionResultArray != null && intersectionResultArray.Size == 1)
					{
						XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
						List<Curve> list2 = this.SplitCurve(list[j], xyzpoint);
						if (list2 != null && list2.Count > 0)
						{
							list.RemoveAt(j);
							list.AddRange(list2);
							j--;
						}
						List<Curve> list3 = this.SplitCurve(list[i], xyzpoint);
						if (list3 != null && list3.Count > 0)
						{
							list.RemoveAt(i);
							list.AddRange(list3);
							i--;
							break;
						}
					}
				}
			}
			return list;
		}

		private List<Curve> SplitCurve(Curve curve, XYZ ptIntersect)
		{
			XYZ endPoint = curve.GetEndPoint(0);
			XYZ endPoint2 = curve.GetEndPoint(1);
			List<Curve> list = new List<Curve>();
			if (ptIntersect.DistanceTo(endPoint) < this.m_dMinDist || ptIntersect.DistanceTo(endPoint2) < this.m_dMinDist)
			{
				return list;
			}
			if (curve.GetType() == typeof(Line))
			{
				list.Add(Line.CreateBound(endPoint, ptIntersect));
				list.Add(Line.CreateBound(ptIntersect, endPoint2));
			}
			else if (curve.GetType() == typeof(Arc))
			{
				Arc arc = curve as Arc;
				XYZ center = arc.Center;
				XYZ normal = arc.Normal;
				XYZ xyz = YJKArch.Utils.Geometry.CalculatMidPoint(endPoint, ptIntersect, center, normal);
				Arc item = Arc.Create(endPoint, ptIntersect, xyz);
				list.Add(item);
				XYZ xyz2 = YJKArch.Utils.Geometry.CalculatMidPoint(ptIntersect, endPoint2, center, normal);
				Arc item2 = Arc.Create(ptIntersect, endPoint2, xyz2);
				list.Add(item2);
			}
			return list;
		}

		private void RemoveRepeatCurves(List<Curve> lstCurve)
		{
			for (int i = 0; i < lstCurve.Count; i++)
			{
				for (int j = i + 1; j < lstCurve.Count; j++)
				{
					SetComparisonResult setComparisonResult = lstCurve[i].Intersect(lstCurve[j]);
					if (64 == (int)setComparisonResult)
					{
						XYZ endPoint = lstCurve[i].GetEndPoint(0);
						XYZ endPoint2 = lstCurve[i].GetEndPoint(1);
						XYZ endPoint3 = lstCurve[j].GetEndPoint(0);
						XYZ endPoint4 = lstCurve[j].GetEndPoint(1);
						if ((endPoint.DistanceTo(endPoint3) < this.m_dMinDist && endPoint2.DistanceTo(endPoint4) < this.m_dMinDist) || (endPoint.DistanceTo(endPoint4) < this.m_dMinDist && endPoint2.DistanceTo(endPoint3) < this.m_dMinDist))
						{
							lstCurve.RemoveAt(j);
							j--;
						}
					}
				}
			}
		}

		private List<DrawingKit.RichPoint> ConstructRichPoint(List<Curve> lstCurve)
		{
			List<DrawingKit.RichPoint> list = new List<DrawingKit.RichPoint>();
			foreach (Curve curve in lstCurve)
			{
				XYZ ptStart = curve.GetEndPoint(0);
				int num = list.FindIndex((DrawingKit.RichPoint a) => a.m_point.DistanceTo(ptStart) < this.m_dMinDist);
				if (-1 == num)
				{
					list.Add(new DrawingKit.RichPoint(ptStart, curve));
				}
				else
				{
					list[num].AddCurve(curve);
				}
				XYZ ptEnd = curve.GetEndPoint(1);
				num = list.FindIndex((DrawingKit.RichPoint a) => a.m_point.DistanceTo(ptEnd) < this.m_dMinDist);
				if (-1 == num)
				{
					list.Add(new DrawingKit.RichPoint(ptEnd, this.CreateReversedCurve(curve)));
				}
				else
				{
					list[num].AddCurve(this.CreateReversedCurve(curve));
				}
			}
			return list;
		}

		private void DeleteSingleEdgePoint(ref List<DrawingKit.RichPoint> lstRichPoint)
		{
			for (int i = 0; i < lstRichPoint.Count; i++)
			{
				DrawingKit.RichPoint richPoint = lstRichPoint[i];
				if (richPoint.m_curves.Count == 0)
				{
					lstRichPoint.RemoveAt(i);
					i--;
				}
				else if (richPoint.m_curves.Count == 1)
				{
					XYZ point = richPoint.m_point;
					XYZ ptNext = richPoint.m_curves[0].GetEndPoint(1);
					lstRichPoint.RemoveAt(i);
					i--;
					DrawingKit.RichPoint richPoint2 = lstRichPoint.Find((DrawingKit.RichPoint a) => a.m_point.DistanceTo(ptNext) < this.m_dMinDist);
					for (int j = 0; j < richPoint2.m_curves.Count; j++)
					{
						if (richPoint2.m_curves[j].GetEndPoint(1).DistanceTo(point) < this.m_dMinDist)
						{
							richPoint2.m_curves.RemoveAt(j);
							break;
						}
					}
				}
			}
			lstRichPoint.TrimExcess();
		}

		private List<Curve> GetLongestPathAreas(List<DrawingKit.RichPoint> lstRichPoint)
		{
			List<Curve> list = new List<Curve>();
			while (lstRichPoint.Count > 1)
			{
				List<Curve> list2 = this.SearchLongestPath(lstRichPoint);
				list.AddRange(list2);
				List<XYZ> list3 = new List<XYZ>();
				foreach (Curve curve in list2)
				{
					list3.AddRange(curve.Tessellate());
				}
				for (int i = 0; i < lstRichPoint.Count; i++)
				{
					if (-1 != YJKArch.Utils.Geometry.PointInPloygon(list3, lstRichPoint[i].m_point, 0.0001, 0.0001))
					{
						lstRichPoint.RemoveAt(i);
						i--;
					}
				}
			}
			return list;
		}

		private Curve CreateReversedCurve(Curve orig)
		{
			if (orig is Line)
			{
				return YJKLineEx.YJKGetBound(orig.GetEndPoint(1), orig.GetEndPoint(0));
			}
			if (orig is Arc)
			{
				return Arc.Create(orig.GetEndPoint(1), orig.GetEndPoint(0), orig.Evaluate(0.5, true));
			}
			throw new Exception("无法创建方向相反的曲线。");
		}

		private List<Curve> SearchLongestPath(List<DrawingKit.RichPoint> lstRichPoint)
		{
			List<Curve> list = new List<Curve>();
			if (lstRichPoint.Count == 0)
			{
				return list;
			}
			Curve curve = null;
			XYZ ptCurrent = lstRichPoint[0].m_point;
			XYZ xyz = XYZ.BasisY.Negate();
			//Predicate<DrawingKit.RichPoint> <>9__0;
			do
			{
				double num = 0.0;
                //Predicate<DrawingKit.RichPoint> match;
                //if ((match = <>9__0) == null)
                //{
                //    match = (<>9__0 = ((DrawingKit.RichPoint a) => a.m_point.DistanceTo(ptCurrent) < this.m_dMinDist));
                //}
                //foreach (Curve curve2 in lstRichPoint.Find(match).m_curves)
                //{
                //    XYZ tangentAtParameter = this.GetTangentAtParameter(curve2, 0.0);
                //    double num2 = xyz.AngleOnPlaneTo(tangentAtParameter, XYZ.BasisZ);
                //    if (Math.Round(Math.PI*2, 4) == Math.Round(num2, 4))
                //    {
                //        num2 = 0.0;
                //    }
                //    if (num2 > num)
                //    {
                //        curve = curve2;
                //        num = num2;
                //    }
                //}
				list.Add(curve);
				ptCurrent = curve.GetEndPoint(1);
				xyz = this.GetTangentAtParameter(this.CreateReversedCurve(curve), 0.0);
			}
			while (ptCurrent.DistanceTo(lstRichPoint[0].m_point) >= this.m_dMinDist);
			return list;
		}

		private XYZ GetTangentAtParameter(Curve curve, double dParameter)
		{
			return curve.ComputeDerivatives(dParameter, true).BasisX.Normalize();
		}

		private void BreakRampBottomLine(List<ElementId> lstRampBotLineId, double dBeamWidth, XYZ ptBeamB, ref XYZ ptBeamT)
		{
			Line otherLine = Line.CreateUnbound(ptBeamB, ptBeamT - ptBeamB);
			foreach (ElementId elementId in lstRampBotLineId)
			{
				DetailLine detailLine = this.m_doc.GetElementById(elementId) as DetailLine;
				Line line = detailLine.GeometryCurve as Line;
				XYZ xyz = new YJKLine(line).IntersectionPoint(otherLine);
				if (xyz != null)
				{
					ptBeamT = xyz;
					XYZ hyendPoint = line.GetEndPoint(0);
					XYZ hyendPoint2 = line.GetEndPoint(1);
					if (xyz.DistanceTo(hyendPoint) < xyz.DistanceTo(hyendPoint2))
					{
						Line line2 = YJKLineEx.YJKGetBound(xyz, hyendPoint2);
						detailLine.SetGeometryCurve(line2, true);
						if (Math.Abs(xyz.X - hyendPoint.X) - dBeamWidth > AssistFunc.mmToFeet(1.0))
						{
							Line line3 = YJKLineEx.YJKGetBound(hyendPoint, xyz);
							DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line3);
							lstRampBotLineId.Add(detailCurve.Id);
							this.m_lstNewElemId.Add(detailCurve.Id);
							break;
						}
						break;
					}
					else
					{
						Line line4 = YJKLineEx.YJKGetBound(hyendPoint, xyz);
						detailLine.SetGeometryCurve(line4, true);
						if (Math.Abs(xyz.X - hyendPoint2.X) - dBeamWidth > AssistFunc.mmToFeet(1.0))
						{
							Line line5 = YJKLineEx.YJKGetBound(xyz, hyendPoint2);
							DetailCurve detailCurve2 = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line5);
							lstRampBotLineId.Add(detailCurve2.Id);
							this.m_lstNewElemId.Add(detailCurve2.Id);
							break;
						}
						break;
					}
				}
			}
		}

		private void GetBeamSize(FamilyInstance beam, ref double dWidth, ref double dHeight)
		{
			Line curve = (beam.Location as LocationCurve).Curve as Line;
			XYZ hyendPoint = curve.GetEndPoint(0);
			XYZ hyendPoint2 = curve.GetEndPoint(1);
			XYZ vec = (hyendPoint2 - hyendPoint).Normalize();
			foreach (object obj in this.GetBeamFaces(beam))
			{
				PlanarFace planarFace = ((Face)obj) as PlanarFace;
				if (!(null == planarFace) && vec.IsParallelTo(planarFace.FaceNormal()))
				{
					EdgeArrayArray edgeLoops = planarFace.EdgeLoops;
					if (edgeLoops.Size == 1)
					{
						EdgeArray edgeArray = edgeLoops.get_Item(0);
						if (edgeArray.Size == 4)
						{
							IEnumerator enumerator2 = edgeArray.GetEnumerator();
							{
								while (enumerator2.MoveNext())
								{
									object obj2 = enumerator2.Current;
									Line line = ((Edge)obj2).AsCurve() as Line;
									if (!(line == null))
									{
										hyendPoint = line.GetEndPoint(0);
										hyendPoint2 = line.GetEndPoint(1);
										double val = hyendPoint.DistanceTo(hyendPoint2);
										if (Math.Abs(hyendPoint.X - hyendPoint2.X) < 0.0001 && Math.Abs(hyendPoint.Y - hyendPoint2.Y) < 0.0001)
										{
											dHeight = Math.Max(dHeight, val);
										}
										if (Math.Abs(hyendPoint.Z - hyendPoint2.Z) < 0.0001)
										{
											dWidth = Math.Max(dWidth, val);
										}
									}
								}
								break;
							}
						}
					}
				}
			}
		}

		private FaceArray GetBeamFaces(FamilyInstance beam)
		{
			FaceArray faceArray = new FaceArray();
			foreach (GeometryObject geometryObject in RevitVersionFuncs.GetGeometryObjectArray(beam.get_Geometry(new Options
			{
				View = this.m_doc.ActiveView
			})))
			{
				if (geometryObject is Solid)
				{
					foreach (object obj in (geometryObject as Solid).Faces)
					{
						Face face = (Face)obj;
						faceArray.Append(face);
					}
				}
			}
			return faceArray;
		}

		private List<FamilyInstance> GetAllBeams()
		{
			List<FamilyInstance> list = new List<FamilyInstance>();
			foreach (Element element in new FilteredElementCollector(this.m_doc).OfClass(typeof(FamilyInstance)).ToElements())
			{
				FamilyInstance familyInstance = element as FamilyInstance;
				if ((int)familyInstance.StructuralType == 1)
				{
					LocationCurve locationCurve = familyInstance.Location as LocationCurve;
					if (locationCurve != null)
					{
						Line line = locationCurve.Curve as Line;
						if (!(line == null))
						{
							XYZ hyendPoint = line.GetEndPoint(0);
							XYZ hyendPoint2 = line.GetEndPoint(1);
							if (!hyendPoint.IsAlmostEqualTo(hyendPoint2, 0.005) && YJKArch.Utils.Geometry.IsEqual(hyendPoint.Z, hyendPoint2.Z))
							{
								list.Add(familyInstance);
							}
						}
					}
				}
			}
			return list;
		}

		private bool IsContainsPoint(List<XYZ> lstPoint, XYZ ptCheck)
		{
			foreach (XYZ xyz in lstPoint)
			{
				if (ptCheck.IsAlmostEqualTo(xyz))
				{
					return true;
				}
			}
			return false;
		}

		private GraphicsStyle LoadLineStyle(string strStyleName)
		{
			GraphicsStyle graphicsStyle = null;
			foreach (Element element in new FilteredElementCollector(this.m_doc).OfClass(typeof(GraphicsStyle)))
			{
				GraphicsStyle graphicsStyle2 = element as GraphicsStyle;
				if (graphicsStyle2 != null)
				{
					if (graphicsStyle2.Name.CompareTo(strStyleName) == 0)
					{
						return graphicsStyle2;
					}
					if (graphicsStyle == null)
					{
						graphicsStyle = graphicsStyle2;
					}
				}
			}
			return graphicsStyle;
		}

		private List<ElementId> DrawAxis(XYZ ptStart, XYZ ptEnd, GraphicsStyle lineStyle, string strAxisName)
		{
			List<ElementId> list = new List<ElementId>();
			Line line = YJKLineEx.YJKGetBound(ptStart, ptEnd);
			DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
			if (detailCurve != null)
			{
				if (lineStyle != null)
				{
					detailCurve.LineStyle = lineStyle;
				}
				this.m_lstAxisId.Add(detailCurve.Id);
				list.Add(detailCurve.Id);
			}
			double num = AssistFunc.mmToFeet(3.5) * (double)this.m_doc.ActiveView.Scale;
			XYZ xyz = (ptEnd - ptStart).Normalize();
			XYZ xyz2 = ptEnd + xyz * num;
			Arc arc = Arc.Create(xyz2, num, 0.0, Math.PI*2, XYZ.BasisX, XYZ.BasisY);
			DetailCurve detailCurve2 = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, arc);
			if (detailCurve2 != null)
			{
				list.Add(detailCurve2.Id);
			}
			XYZ origin = xyz2 + XYZ.BasisY * 0.65 * num;
            TextAlignFlags textAlign = (TextAlignFlags)128;
			TextNote textNode = this.m_doc.GetTextNode(this.m_doc.ActiveView, origin, XYZ.BasisX, XYZ.BasisY, 2.0 * num, textAlign, strAxisName, this.m_textType);
			if (textNode != null)
			{
				list.Add(textNode.Id);
			}
			return list;
		}

		private double GetCurveLengthAtPoint(Curve curve, XYZ ptOnCurve)
		{
			XYZ hyendPoint = curve.GetEndPoint(0);
			if (hyendPoint.DistanceTo(ptOnCurve) < 0.0035)
			{
				return 0.0;
			}
			double result = 0.0;
			if (curve is Line)
			{
				result = hyendPoint.DistanceTo(ptOnCurve);
			}
			else if (curve is Arc)
			{
				Arc arc = curve as Arc;
				XYZ xyz = YJKArch.Utils.Geometry.CalculatMidPoint(hyendPoint, ptOnCurve, arc.Center, arc.Normal);
				Arc arc2 = Arc.Create(hyendPoint, ptOnCurve, xyz);
				if (arc2 != null)
				{
					result = arc2.Length;
				}
			}
			return result;
		}

		private double GetSegmentMinElevation()
		{
			double num = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Value[0].StartElevation;
			foreach (KeyValuePair<Level, List<SegmentData>> keyValuePair in this.m_lstAllSegmentData)
			{
				List<SegmentData> value = keyValuePair.Value;
				for (int i = 0; i < value.Count; i++)
				{
					SegmentData segmentData = value[i];
					double num2 = Math.Min(segmentData.StartElevation, segmentData.EndElevation);
					if (YJKArch.Utils.Geometry.GreaterThan(num, num2))
					{
						num = num2;
					}
				}
			}
			return num;
		}

		private double GetSegmentMaxElevation()
		{
			double num = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Value[0].StartElevation;
			foreach (KeyValuePair<Level, List<SegmentData>> keyValuePair in this.m_lstAllSegmentData)
			{
				List<SegmentData> value = keyValuePair.Value;
				for (int i = 0; i < value.Count; i++)
				{
					SegmentData segmentData = value[i];
					double num2 = Math.Max(segmentData.StartElevation, segmentData.EndElevation);
					if (YJKArch.Utils.Geometry.LessThan(num, num2))
					{
						num = num2;
					}
				}
			}
			return num;
		}

		private List<Level> GetAllLevel()
		{
			return (from l in new FilteredElementCollector(this.m_doc).OfClass(typeof(Level))
			select l as Level).ToList<Level>();
		}

		private List<ElementId> FindRampBottomLine(XYZ ptRampBottom)
		{
			List<ElementId> list = new List<ElementId>();
			ElementId elementId = null;
			XYZ xyz = null;
			XYZ xyz2 = null;
			foreach (ElementId elementId2 in this.m_lstNewElemId)
			{
				DetailLine detailLine = this.m_doc.GetElementById(elementId2) as DetailLine;
				if (detailLine != null)
				{
					Line line = detailLine.GeometryCurve as Line;
					xyz = line.GetEndPoint(0);
					xyz2 = line.GetEndPoint(1);
					if (Math.Abs(xyz.X - xyz2.X) >= 0.0001 && line.Project(ptRampBottom).XYZPoint.DistanceTo(ptRampBottom) < AssistFunc.mmToFeet(5.0))
					{
						elementId = elementId2;
						break;
					}
				}
			}
			if (elementId != null)
			{
				list.Add(elementId);
				foreach (ElementId elementId3 in this.m_lstNewElemId)
				{
					if (!(elementId3 == elementId))
					{
						DetailLine detailLine2 = this.m_doc.GetElementById(elementId3) as DetailLine;
						if (detailLine2 != null)
						{
							Line curve = detailLine2.GeometryCurve as Line;
							XYZ hyendPoint = curve.GetEndPoint(0);
							XYZ hyendPoint2 = curve.GetEndPoint(1);
							if (Math.Abs(hyendPoint.X - hyendPoint2.X) >= 0.0001)
							{
								double num = AssistFunc.mmToFeet(3.0);
								if (hyendPoint.DistanceTo(xyz) < num || hyendPoint2.DistanceTo(xyz) < num || hyendPoint.DistanceTo(xyz2) < num || hyendPoint2.DistanceTo(xyz2) < num)
								{
									list.Add(elementId3);
								}
							}
						}
					}
				}
			}
			return list;
		}

		private FilledRegion FindNearSegmentRegion(XYZ ptRampBottom)
		{
			foreach (ElementId elementId in this.m_lstNewElemId)
			{
				FilledRegion filledRegion = this.m_doc.GetElementById(elementId) as FilledRegion;
				if (filledRegion != null)
				{
					List<Curve> list = new List<Curve>();
					foreach (CurveLoop loop in filledRegion.GetBoundaries())
					{
						list.AddRange(this.GetCurveLoopCurves(loop));
					}
					XYZ pt = ptRampBottom + XYZ.BasisY * AssistFunc.mmToFeet(5.0);
					if (YJKRGeometry.Geometry.PointInPloygon(list, pt) == 1)
					{
						return filledRegion;
					}
				}
			}
			return null;
		}

		private Dictionary<XYZ, Grid> GetIntersecGrids(List<Grid> lstAllGrid, Curve RampCurve)
		{
			double z = RampCurve.GetEndPoint(0).Z;
			Dictionary<XYZ, Grid> dictionary = new Dictionary<XYZ, Grid>();
			foreach (Grid grid in lstAllGrid)
			{
				Curve curve = null;
				Curve curve2 = grid.Curve;
				XYZ hyendPoint = curve2.GetEndPoint(0);
				XYZ hyendPoint2 = curve2.GetEndPoint(1);
				if (curve2 is Line)
				{
					curve = YJKLineEx.YJKGetBound(new XYZ(hyendPoint.X, hyendPoint.Y, z), new XYZ(hyendPoint2.X, hyendPoint2.Y, z));
				}
				else if (curve2 is Arc)
				{
					XYZ arcMidPoint = ArcAssistFunc.GetArcMidPoint(curve2 as Arc);
					curve = Arc.Create(new XYZ(hyendPoint.X, hyendPoint.Y, z), new XYZ(hyendPoint2.X, hyendPoint2.Y, z), new XYZ(arcMidPoint.X, arcMidPoint.Y, z));
				}
				IntersectionResultArray intersectionResultArray = null;
				curve.Intersect(RampCurve, out intersectionResultArray);
				if (intersectionResultArray != null && intersectionResultArray.Size > 0)
				{
					foreach (object obj in intersectionResultArray)
					{
						IntersectionResult intersectionResult = (IntersectionResult)obj;
						dictionary.Add(intersectionResult.XYZPoint, grid);
					}
				}
			}
			return dictionary;
		}

		private Dictionary<XYZ, FamilyInstance> GetIntersecBeams(List<FamilyInstance> lstAllBeam, Curve RampCurve, double dRampStartElev, double dRampEndElev, double dRampThick)
		{
			double z = RampCurve.GetEndPoint(0).Z;
			double z2 = RampCurve.GetEndPoint(1).Z;
			Dictionary<XYZ, FamilyInstance> dictionary = new Dictionary<XYZ, FamilyInstance>();
			foreach (FamilyInstance familyInstance in lstAllBeam)
			{
				LocationCurve locationCurve = familyInstance.Location as LocationCurve;
				if (locationCurve != null)
				{
					Line line = locationCurve.Curve as Line;
					if (!(line == null))
					{
						XYZ hyendPoint = line.GetEndPoint(0);
						XYZ hyendPoint2 = line.GetEndPoint(1);
						if (Math.Abs(hyendPoint.Z - hyendPoint2.Z) <= 0.0001)
						{
							double num = 0.0;
							double num2 = 0.0;
							this.GetBeamSize(familyInstance, ref num, ref num2);
							if (num != 0.0 || num2 != 0.0)
							{
								Parameter parameter = familyInstance.GetParameter(BuiltInParameter.STRUCTURAL_ELEVATION_AT_BOTTOM);
								if (parameter != null)
								{
									double num3 = parameter.AsDouble();
									double num4 = num3 + num2;
									double num5 = num3 + 0.5 * num2;
									Curve curve = YJKLineEx.YJKGetBound(new XYZ(hyendPoint.X, hyendPoint.Y, z), new XYZ(hyendPoint2.X, hyendPoint2.Y, z));
									IntersectionResultArray intersectionResultArray = null;
									curve.Intersect(RampCurve, out intersectionResultArray);
									if (intersectionResultArray != null && intersectionResultArray.Size >= 1)
									{
										foreach (object obj in intersectionResultArray)
										{
											IntersectionResult intersectionResult = (IntersectionResult)obj;
											double curveLengthAtPoint = this.GetCurveLengthAtPoint(RampCurve, intersectionResult.XYZPoint);
											double num6 = dRampStartElev + (dRampEndElev - dRampStartElev) * curveLengthAtPoint / RampCurve.Length - 0.5 * dRampThick;
											double num7 = Math.Abs(num5 - num6);
											double num8 = dRampThick + num4 - num3;
											if (num7 < 0.5 * num8 + AssistFunc.mmToFeet(5.0))
											{
												dictionary.Add(intersectionResult.XYZPoint, familyInstance);
											}
										}
									}
								}
							}
						}
					}
				}
			}
			return dictionary;
		}

		private List<ElementId> DrawDimension(XYZ ptDim1, XYZ ptDim2, XYZ ptLeader)
		{
			List<ElementId> list = new List<ElementId>();
			ReferenceArray referenceArray = new ReferenceArray();
			XYZ xyz = (ptLeader - ptDim1).Normalize();
			XYZ endPoint = ptDim1 + xyz * AssistFunc.mmToFeet(10.0);
			Line line = YJKLineEx.YJKGetBound(ptDim1, endPoint);
			DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
			list.Add(detailCurve.Id);
			referenceArray.Append(detailCurve.GeometryCurve.Reference);
			XYZ endPoint2 = ptDim2 + xyz * AssistFunc.mmToFeet(10.0);
			Line line2 = YJKLineEx.YJKGetBound(ptDim2, endPoint2);
			DetailCurve detailCurve2 = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line2);
			list.Add(detailCurve2.Id);
			referenceArray.Append(detailCurve2.GeometryCurve.Reference);
			XYZ endPoint3 = ptDim2 + (ptLeader - ptDim1);
			Line line3 = YJKLineEx.YJKGetBound(ptLeader, endPoint3);
			Dimension dimension = this.m_doc.Create.NewDimension(this.m_doc.ActiveView, line3, referenceArray, this.m_dimType);
			list.Add(dimension.Id);
			return list;
		}

		private List<ElementId> DrawDimensions(List<XYZ> lstDimPt, XYZ ptLeader)
		{
			List<ElementId> list = new List<ElementId>();
			List<XYZ> list2 = this.MoveSamePoint(lstDimPt);
			if (list2.Count < 2)
			{
				return list;
			}
			XYZ xyz = list2[1] - list2[0];
			XYZ xyz2 = ptLeader + 100.0 * xyz;
			Line line = Line.CreateBound(ptLeader, xyz2);
			ReferenceArray referenceArray = this.CreateDimRefs(list2, ptLeader);
			Dimension dimension = this.m_doc.Create.NewDimension(this.m_doc.ActiveView, line, referenceArray, this.m_dimType);
			if (dimension != null)
			{
				RevitDimensionExtension.ResetDimTextPos(dimension);
				list.Add(dimension.Id);
			}
			return list;
		}

		private List<ElementId> DrawGradient(XYZ ptTopStart, XYZ ptTopEnd)
		{
			List<ElementId> list = new List<ElementId>();
			double num = Math.Abs(ptTopEnd.X - ptTopStart.X);
			double num2 = Math.Abs(ptTopEnd.Y - ptTopStart.Y);
			if (YJKArch.Utils.Geometry.LessThan(num2, 0.003))
			{
				return list;
			}
			string text = string.Empty;
			if (this.m_nSlopeType == 1)
			{
				text = this.DoubleToString(100.0 * (num2 / num), "f2") + "%";
			}
			else if (this.m_nSlopeType == 2)
			{
				text = "1:" + this.DoubleToString(num / num2, "f2");
			}
			double num3 = AssistFunc.mmToFeet(250.0);
			double num4 = (double)text.Length;
			double num5 = Math.Atan2(num2, num);
			double num6 = this.m_textType.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble() * (double)this.m_doc.ActiveView.Scale;
			double num7 = num6 / RevitDocumentExtension.GetVersionTextWidthFactory();
			XYZ xyz = YJKArch.Utils.Geometry.CalculatMidPoint(ptTopStart, ptTopEnd) + XYZ.BasisY * num3 * 3.0;
			XYZ xyz2;
			XYZ xyz3;
			XYZ endPoint;
			XYZ origin;
			XYZ xyz5;
			if (YJKArch.Utils.Geometry.LessThan(ptTopEnd.Y, ptTopStart.Y))
			{
				xyz2 = YJKArch.Utils.Geometry.RotateTo(XYZ.BasisX, -num5, XYZ.BasisZ);
				xyz3 = YJKArch.Utils.Geometry.RotateTo(xyz2, Math.PI*.5, XYZ.BasisZ);
				xyz += xyz2 * (num3 + num4 / 2.0);
				XYZ xyz4 = xyz - xyz2 * num3 * 2.0;
				endPoint = xyz4 - xyz2 * num4;
				origin = xyz4 - xyz2 * (num4 / 2.0) + xyz3 * 2.5 * num7;
				xyz5 = xyz - xyz2 * num3;
			}
			else
			{
				xyz2 = YJKArch.Utils.Geometry.RotateTo(XYZ.BasisX, num5, XYZ.BasisZ);
				xyz3 = YJKArch.Utils.Geometry.RotateTo(xyz2, Math.PI*.5, XYZ.BasisZ);
				xyz -= xyz2 * (num3 + num4 / 2.0);
				XYZ xyz6 = xyz + xyz2 * num3 * 2.0;
				endPoint = xyz6 + xyz2 * num4;
				origin = xyz6 + xyz2 * (num4 / 2.0) + xyz3 * 2.5 * num7;
				xyz5 = xyz + xyz2 * num3;
			}
			double lineWidth = num4 * num6 / (double)this.m_doc.ActiveView.Scale;
            TextNote textNode = this.m_doc.GetTextNode(this.m_doc.ActiveView, origin, xyz2, xyz3, lineWidth, (TextAlignFlags)128, text);
			textNode.TextNoteType = this.m_textType;
			list.Add(textNode.Id);
			Line line = YJKLineEx.YJKGetBound(xyz, endPoint);
			DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
			list.Add(detailCurve.Id);
			double num8 = num3 / 6.0;
			XYZ xyz7 = YJKArch.Utils.Geometry.RotateTo(xyz2, Math.PI*.5, XYZ.BasisZ) * num8;
			XYZ item = xyz5 + xyz7;
			XYZ item2 = xyz5 - xyz7;
			List<XYZ> list2 = new List<XYZ>();
			list2.Add(xyz);
			list2.Add(item);
			list2.Add(item2);
			FilledRegionType arrowFillType = this.GetArrowFillType();
			if (arrowFillType != null)
			{
				ElementId elementId = this.DrawFilledRegin(list2, arrowFillType.Id);
				if (null != elementId)
				{
					list.Add(elementId);
				}
			}
			foreach (ElementId elemColorByDimType in list)
			{
				this.SetElemColorByDimType(elemColorByDimType);
			}
			return list;
		}

		private List<ElementId> DrawFloorFill(List<Curve> lstTopCurve, List<Curve> lstBottomCurve)
		{
			List<ElementId> list = new List<ElementId>();
			CompoundStructureLayer compoundStructureLayer = null;
			CompoundStructureLayer compoundStructureLayer2 = null;
			this.GetFloorTypeLayer(this.m_floorType, ref compoundStructureLayer, ref compoundStructureLayer2);
			if (compoundStructureLayer != null && compoundStructureLayer.Width > 0.005)
			{
				if (compoundStructureLayer2 == null || compoundStructureLayer2.Width < 0.005)
				{
					ElementId fillReginTypeId = this.GetFillReginTypeId(compoundStructureLayer.MaterialId);
					list.AddRange(this.FillCurves(fillReginTypeId, lstTopCurve, lstBottomCurve));
				}
				else
				{
					XYZ endPoint = lstTopCurve[0].GetEndPoint(0);
					double num = lstBottomCurve[0].GetEndPoint(0).DistanceTo(endPoint);
					double floorThick = this.GetFloorThick(this.m_floorType);
					double dDistance = num * compoundStructureLayer.Width / floorThick;
					XYZ vtOffset = new XYZ(0.0, -1.0, 0.0);
					List<Curve> list2 = this.OffsetCurves(lstTopCurve, vtOffset, dDistance);
					if (!this.IsTwoCurveGroupIntersect(list2, lstBottomCurve))
					{
						ElementId fillReginTypeId2 = this.GetFillReginTypeId(compoundStructureLayer.MaterialId);
						list.AddRange(this.FillCurves(fillReginTypeId2, lstTopCurve, list2));
						ElementId fillReginTypeId3 = this.GetFillReginTypeId(compoundStructureLayer2.MaterialId);
						list.AddRange(this.FillCurves(fillReginTypeId3, list2, lstBottomCurve));
					}
					else
					{
						ElementId fillReginTypeId4 = this.GetFillReginTypeId(compoundStructureLayer2.MaterialId);
						list.AddRange(this.FillCurves(fillReginTypeId4, lstTopCurve, lstBottomCurve));
					}
				}
			}
			else if (compoundStructureLayer2 != null && compoundStructureLayer2.Width > 0.005)
			{
				ElementId fillReginTypeId5 = this.GetFillReginTypeId(compoundStructureLayer2.MaterialId);
				list.AddRange(this.FillCurves(fillReginTypeId5, lstTopCurve, lstBottomCurve));
			}
			return list;
		}

		private List<ElementId> DrawElevation(XYZ ptPosition, double dElevation, bool bRight = true)
		{
			string text = (dElevation / 1000.0).ToString("f3");
			if (dElevation >= -1E-06 && dElevation <= 1E-06)
			{
				text = "±" + text;
			}
			string strFamilyName = "符号_普通标高-带基线(右上)";
			if (!bRight)
			{
				strFamilyName = "符号_普通标高-带基线(左上)";
			}
			List<ElementId> list = new List<ElementId>();
			FamilySymbol levelDimFamilySymbol = this.GetLevelDimFamilySymbol(strFamilyName);
			if (levelDimFamilySymbol != null)
			{
				UnifiedModified.ActivateFamilySymbol(levelDimFamilySymbol);
				FamilyInstance familyInstance = this.m_doc.Create.NewFamilyInstance(ptPosition, levelDimFamilySymbol, this.m_doc.ActiveView);
				if (familyInstance != null)
				{
					familyInstance.GetParameter("标高说明").Set("");
					familyInstance.GetParameter("标高说明可见性").Set(0);
					familyInstance.GetParameter("标高1").Set(text);
					this.SetElemColorByDimType(familyInstance.Id);
					list.Add(familyInstance.Id);
				}
			}
			return list;
		}

		private List<ElementId> DrawElevation(XYZ ptPosition, Level floorLevel, bool bRight = true)
		{
			double num = AssistFunc.feetToMM(floorLevel.Elevation) / 1000.0;
			string text = floorLevel.Name;
			string text2 = num.ToString("f3");
			if (num >= -1E-06 && num <= 1E-06)
			{
				text2 = "±" + text2;
			}
			string strFamilyName = "符号_普通标高-带基线(右上)";
			if (!bRight)
			{
				strFamilyName = "符号_普通标高-带基线(左上)";
			}
			List<ElementId> list = new List<ElementId>();
			FamilySymbol levelDimFamilySymbol = this.GetLevelDimFamilySymbol(strFamilyName);
			if (levelDimFamilySymbol != null)
			{
				UnifiedModified.ActivateFamilySymbol(levelDimFamilySymbol);
				FamilyInstance familyInstance = this.m_doc.Create.NewFamilyInstance(ptPosition, levelDimFamilySymbol, this.m_doc.ActiveView);
				if (familyInstance != null)
				{
					if (string.IsNullOrEmpty(text))
					{
						familyInstance.GetParameter("标高说明").Set("");
						familyInstance.GetParameter("标高说明可见性").Set(0);
					}
					else
					{
						text = "(" + text + ")";
						familyInstance.GetParameter("标高说明").Set(text);
						familyInstance.GetParameter("标高说明可见性").Set(1);
					}
					familyInstance.GetParameter("标高1").Set(text2);
					this.SetElemColorByDimType(familyInstance.Id);
					list.Add(familyInstance.Id);
				}
			}
			return list;
		}

		private List<ElementId> DrawRadiusDim(Arc dimArc)
		{
			List<ElementId> list = new List<ElementId>();
			XYZ center = dimArc.Center;
			XYZ xyz = dimArc.Evaluate(0.5, true);
			XYZ xyz2 = (xyz - center).Normalize();
			double dValue = AssistFunc.feetToMM(dimArc.Radius);
			double num = AssistFunc.mmToFeet(250.0);
			double num2 = num / 6.0;
			double num3 = 5.0 * num;
			double num4 = this.m_textType.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble() * (double)this.m_doc.ActiveView.Scale;
			double num5 = num4 / RevitDocumentExtension.GetVersionTextWidthFactory();
			XYZ xyz3 = xyz - xyz2 * num3;
			XYZ xyz4 = xyz - xyz2 * num;
			Line line = YJKLineEx.YJKGetBound(xyz3, xyz4);
			DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
			list.Add(detailCurve.Id);
			string text = "R " + this.DoubleToString(dValue, "f0");
			double angle = (xyz.X < center.X) ? -Math.PI*.5 : Math.PI*.5;
			XYZ xyz5 = YJKArch.Utils.Geometry.RotateTo(xyz2, angle, XYZ.BasisZ);
			XYZ baseVec = (xyz.X < center.X) ? (-xyz2) : xyz2;
			XYZ xyz6 = xyz3 + xyz2 * (num3 / 2.0);
			xyz6 += xyz5 * 2.5 * num5;
			double lineWidth = (double)text.Length * num4 / (double)this.m_doc.ActiveView.Scale;
            TextNote textNode = this.m_doc.GetTextNode(this.m_doc.ActiveView, xyz6, baseVec, xyz5, lineWidth, (TextAlignFlags)128, text);
			textNode.TextNoteType = this.m_textType;
			list.Add(textNode.Id);
			XYZ xyz7 = YJKArch.Utils.Geometry.RotateTo(xyz2, Math.PI*.5, XYZ.BasisZ);
			XYZ item = xyz4 + xyz7 * num2;
			XYZ item2 = xyz4 - xyz7 * num2;
			List<XYZ> list2 = new List<XYZ>();
			list2.Add(xyz);
			list2.Add(item);
			list2.Add(item2);
			FilledRegionType arrowFillType = this.GetArrowFillType();
			if (arrowFillType != null)
			{
				ElementId elementId = this.DrawFilledRegin(list2, arrowFillType.Id);
				if (null != elementId)
				{
					list.Add(elementId);
				}
			}
			foreach (ElementId elemColorByDimType in list)
			{
				this.SetElemColorByDimType(elemColorByDimType);
			}
			return list;
		}

		private List<CurveInfo> CreateArrows(YJKArch.Utils.EdgeInfo centerCurve, double dLeftWidth, double dRightWidth)
		{
			List<CurveInfo> list = new List<CurveInfo>();
			XYZ startPoint = centerCurve.StartPoint;
			XYZ endPoint = centerCurve.EndPoint;
			float lineWidth = 2f;
			if (!centerCurve.IsArc)
			{
				XYZ xyz = (centerCurve.EndPoint - centerCurve.StartPoint).Normalize();
				double num = Math.Min(dLeftWidth, dRightWidth);
				XYZ xyz2 = YJKArch.Utils.Geometry.RotateTo(-xyz, 0.52359877559829882, XYZ.BasisZ).Normalize() * num;
				XYZ xyz3 = YJKArch.Utils.Geometry.RotateTo(-xyz, -0.52359877559829882, XYZ.BasisZ).Normalize() * num;
				Line curve = YJKLineEx.YJKGetBound(startPoint, endPoint);
				list.Add(new CurveInfo(curve, PenColor.PC_Black, lineWidth));
				Line curve2 = YJKLineEx.YJKGetBound(endPoint, endPoint + xyz3);
				list.Add(new CurveInfo(curve2, PenColor.PC_Black, lineWidth));
				Line curve3 = YJKLineEx.YJKGetBound(endPoint, endPoint + xyz2);
				list.Add(new CurveInfo(curve3, PenColor.PC_Black, lineWidth));
			}
			else
			{
				XYZ center = centerCurve.Center;
				XYZ normal = centerCurve.Normal;
				XYZ radianPnt = YJKArch.Utils.Geometry.CalculatMidPoint(startPoint, endPoint, center, normal);
				double radius = centerCurve.Radius;
				XYZ pt = (endPoint - center).Normalize();
				double num2 = Math.Min(dLeftWidth, dRightWidth);
				XYZ xyz4 = YJKArch.Utils.Geometry.RotateTo(pt, -1.0471975511965976, XYZ.BasisZ).Normalize() * num2;
				XYZ xyz5 = YJKArch.Utils.Geometry.RotateTo(pt, -2.0943951023931953, XYZ.BasisZ).Normalize() * num2;
				Arc curve4 = this.m_app.CreatYJKArc(startPoint, endPoint, radianPnt);
				list.Add(new CurveInfo(curve4, PenColor.PC_Black, lineWidth));
				XYZ endPoint2 = endPoint - xyz5;
				if (normal.IsAlmostEqualTo(XYZ.BasisZ))
				{
					endPoint2 = endPoint + xyz5;
				}
				Line curve5 = YJKLineEx.YJKGetBound(endPoint, endPoint2);
				list.Add(new CurveInfo(curve5, PenColor.PC_Black, lineWidth));
				XYZ endPoint3 = endPoint - xyz4;
				if (normal.IsAlmostEqualTo(XYZ.BasisZ))
				{
					endPoint3 = endPoint + xyz4;
				}
				Line curve6 = YJKLineEx.YJKGetBound(endPoint, endPoint3);
				list.Add(new CurveInfo(curve6, PenColor.PC_Black, lineWidth));
			}
			return list;
		}

		private List<ElementId> FillCurves(ElementId fillITyped, List<Curve> lstTopCurve, List<Curve> lstBottomCurve)
		{
			List<ElementId> list = new List<ElementId>();
			if (this.IsTwoCurveGroupIntersect(lstTopCurve, lstBottomCurve))
			{
				return list;
			}
			if (fillITyped != null)
			{
				XYZ hyendPoint = lstTopCurve.First<Curve>().GetEndPoint(0);
				XYZ hyendPoint2 = lstTopCurve.Last<Curve>().GetEndPoint(1);
				XYZ hyendPoint3 = lstBottomCurve.First<Curve>().GetEndPoint(0);
				XYZ hyendPoint4 = lstBottomCurve.Last<Curve>().GetEndPoint(1);
				List<Curve> list2 = new List<Curve>();
				list2.AddRange(lstTopCurve);
				list2.Add(YJKLineEx.YJKGetBound(hyendPoint2, hyendPoint4));
				list2.AddRange(this.ReverseCurves(lstBottomCurve));
				list2.Add(YJKLineEx.YJKGetBound(hyendPoint3, hyendPoint));
				ElementId elementId = this.DrawFilledRegin(list2, fillITyped);
				if (elementId != null)
				{
					list.Add(elementId);
				}
			}
			else
			{
				foreach (Curve curve in lstBottomCurve)
				{
					DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, curve);
					if (detailCurve != null)
					{
						list.Add(detailCurve.Id);
					}
				}
			}
			return list;
		}

		private ElementId DrawFilledRegin(List<XYZ> lstLoopPt, ElementId filledRegionTypeId)
		{
			CurveLoop curveLoop = new CurveLoop();
			for (int i = 0; i < lstLoopPt.Count; i++)
			{
				XYZ startPoint = lstLoopPt[i];
				XYZ endPoint;
				if (i == lstLoopPt.Count - 1)
				{
					endPoint = lstLoopPt[0];
				}
				else
				{
					endPoint = lstLoopPt[i + 1];
				}
				Line line = YJKLineEx.YJKGetBound(startPoint, endPoint);
				curveLoop.Append(line);
			}
			List<CurveLoop> list = new List<CurveLoop>();
			list.Add(curveLoop);
			ElementId result;
			try
			{
				result = FilledRegion.Create(this.m_doc, filledRegionTypeId, this.m_doc.ActiveView.Id, list).Id;
			}
			catch
			{
				result = null;
			}
			return result;
		}

		private ElementId DrawFilledRegin(List<Curve> lstLoopCurve, ElementId filledRegionTypeId)
		{
			ElementId result;
			try
			{
				CurveLoop item = CurveLoop.Create(lstLoopCurve);
				List<CurveLoop> list = new List<CurveLoop>();
				list.Add(item);
				result = FilledRegion.Create(this.m_doc, filledRegionTypeId, this.m_doc.ActiveView.Id, list).Id;
			}
			catch
			{
				result = null;
			}
			return result;
		}

		private ElementId GetFillReginTypeId(ElementId materialId)
		{
			string text = string.Empty;
			if (materialId != null && materialId.IntegerValue != -1)
			{
				Element elementById = this.m_doc.GetElementById(materialId);
				if (elementById != null)
				{
					Material material = elementById as Material;
					if (material != null)
					{
						text = material.Name;
					}
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				text = "无";
			}
			return this.GetFillRegionTypeId(text);
		}

		private ElementId CreateLine(XYZ ptStart, XYZ ptEnd)
		{
			if (ptStart.DistanceTo(ptEnd) < AssistFunc.mmToFeet(1.0))
			{
				return null;
			}
			ElementId result = null;
			Line line = YJKLineEx.YJKGetBound(ptStart, ptEnd);
			DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line);
			if (detailCurve != null)
			{
				result = detailCurve.Id;
			}
			return result;
		}

		private ElementId GetFillRegionTypeId(string strMaterialName)
		{
			if (string.IsNullOrEmpty(strMaterialName))
			{
				return null;
			}
			string empty = string.Empty;
			string empty2 = string.Empty;
			string text = string.Empty;
			if (this.ReadXmlFillRegion(strMaterialName, ref empty, ref empty2))
			{
				text = (((double)this.m_doc.ActiveView.Scale > 100.0) ? empty2 : empty);
			}
			else
			{
				List<Element> list = (from e in new FilteredElementCollector(this.m_doc).OfClass(typeof(Material))
				where e.Name == strMaterialName
				select e).ToList<Element>();
				if (list.Count > 0)
				{
					Material material = list[0] as Material;
					Element element = this.m_doc.GetElement(material.CutPatternId);
					if (element != null)
					{
						text = (element as FillPatternElement).GetFillPattern().Name;
					}
				}
			}
			ElementId result = null;
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			foreach (Element element2 in new FilteredElementCollector(this.m_doc).OfClass(typeof(FilledRegionType)).ToList<Element>())
			{
				FilledRegionType filledRegionType = element2 as FilledRegionType;
				Parameter parameter = filledRegionType.GetParameter(BuiltInParameter.ANY_PATTERN_ID_PARAM_NO_NO);
				if (parameter != null)
				{
					Element elementById = this.m_doc.GetElementById(parameter.AsElementId());
					if (elementById != null && elementById.Name == text)
					{
						result = filledRegionType.Id;
						break;
					}
				}
			}
			return result;
		}

		private List<XYZ> MoveSamePoint(List<XYZ> lstPoint)
		{
			List<XYZ> list = new List<XYZ>();
			foreach (XYZ xyz in lstPoint)
			{
				if (!this.IsHasPoint(list, xyz))
				{
					list.Add(xyz);
				}
			}
			return list;
		}

		private List<Curve> OffsetCurves(List<Curve> lstOldCurve, XYZ vtOffset, double dDistance)
		{
			List<Curve> list = new List<Curve>();
			for (int i = 0; i < lstOldCurve.Count; i++)
			{
				Curve curve = this.OffsetCurve(lstOldCurve[i], vtOffset, dDistance);
				if (curve != null)
				{
					list.Add(curve);
				}
			}
			return list;
		}

		private List<Curve> ReverseCurves(List<Curve> lstOldCurve)
		{
			List<Curve> list = new List<Curve>();
			for (int i = lstOldCurve.Count - 1; i >= 0; i--)
			{
				Curve curve = this.CreateReversedCurve(lstOldCurve[i]);
				if (curve != null)
				{
					list.Add(curve);
				}
			}
			return list;
		}

		private Curve OffsetCurve(Curve oldCurve, XYZ vtOffset, double dDistance)
		{
			if (oldCurve is Line)
			{
				Line curve = oldCurve as Line;
				XYZ xyz = curve.GetEndPoint(0);
				XYZ xyz2 = curve.GetEndPoint(1);
				xyz += vtOffset.Normalize() * dDistance;
				xyz2 += vtOffset.Normalize() * dDistance;
				return YJKLineEx.YJKGetBound(xyz, xyz2);
			}
			if (oldCurve is Arc)
			{
				Arc arc = oldCurve as Arc;
				XYZ xyz3 = arc.GetEndPoint(0);
				XYZ xyz4 = arc.GetEndPoint(1);
				XYZ xyz5 = arc.Evaluate(0.5, true);
				xyz3 += vtOffset.Normalize() * dDistance;
				xyz4 += vtOffset.Normalize() * dDistance;
				xyz5 += vtOffset.Normalize() * dDistance;
				return Arc.Create(xyz3, xyz4, xyz5);
			}
			return null;
		}

		private ReferenceArray CreateDimRefs(List<XYZ> lstDimPt, XYZ ptLeader)
		{
			ReferenceArray referenceArray = new ReferenceArray();
			if (lstDimPt.Count < 2)
			{
				return referenceArray;
			}
			XYZ xyz = lstDimPt[1] - lstDimPt[0];
			XYZ xyz2 = (Line.CreateUnbound(ptLeader, xyz).Project(lstDimPt[0]).XYZPoint - lstDimPt[0]).Normalize();
			XYZ xyz3 = lstDimPt[0] + xyz2 * AssistFunc.mmToFeet(10.0);
			XYZ xyz4 = lstDimPt[1] + xyz2 * AssistFunc.mmToFeet(10.0);
			Line line = Line.CreateBound(xyz3, xyz4);
			line.MakeUnbound();
			foreach (XYZ xyz5 in lstDimPt)
			{
				XYZ xyzpoint = line.Project(xyz5).XYZPoint;
				Line line2 = YJKLineEx.YJKGetBound(xyz5, xyzpoint);
				DetailCurve detailCurve = this.m_doc.Create.NewDetailCurve(this.m_doc.ActiveView, line2);
				referenceArray.Append(detailCurve.GeometryCurve.Reference);
				this.m_lstNewElemId.Add(detailCurve.Id);
			}
			return referenceArray;
		}

		private Reference GetNearAxisRef(XYZ ptDim, List<XYZ> lstDimPt, double dMinSpace)
		{
			Reference result = null;
			double num = 0.0;
			foreach (ElementId elementId in this.m_lstAxisId)
			{
				DetailLine detailLine = this.m_doc.GetElementById(elementId) as DetailLine;
				if (detailLine != null)
				{
					Line line = detailLine.GeometryCurve as Line;
					if (!(line == null))
					{
						XYZ xyzpoint = line.Project(ptDim).XYZPoint;
						double num2 = ptDim.DistanceTo(xyzpoint);
						if (num2 <= dMinSpace && num2 >= AssistFunc.mmToFeet(10.0))
						{
							bool flag = false;
							foreach (XYZ xyz in lstDimPt)
							{
								XYZ xyzpoint2 = line.Project(xyz).XYZPoint;
								if (xyz.DistanceTo(xyzpoint2) < AssistFunc.mmToFeet(10.0))
								{
									flag = true;
									break;
								}
							}
							if (!flag && (num < 0.001 || num > num2))
							{
								result = line.Reference;
								num = num2;
							}
						}
					}
				}
			}
			return result;
		}

		private FamilySymbol GetLevelDimFamilySymbol(string strFamilyName)
		{
			FamilySymbol familySymbol = null;
			if (string.IsNullOrEmpty(strFamilyName))
			{
				return familySymbol;
			}
			familySymbol = YJKRevitTools.GetFamilySymbol(strFamilyName, this.m_doc);
			if (familySymbol == null)
			{
				string versionNumber = this.m_doc.Application.VersionNumber;
				string text = Path.Combine(Product.FamilyLocation, versionNumber, "LevelDimension\\LevelSymbol\\" + strFamilyName + ".rfa");
				if (!File.Exists(text))
				{
					return familySymbol;
				}
				Family family = null;
				this.m_doc.LoadFamily(text, out family);
				familySymbol = YJKRevitTools.GetFamilySymbol(strFamilyName, this.m_doc);
			}
			return familySymbol;
		}

		private FilledRegionType GetArrowFillType()
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_doc).OfClass(typeof(FilledRegionType));
			FilledRegionType filledRegionType = null;
			FilledRegionType filledRegionType2 = null;
			foreach (Element element in filteredElementCollector)
			{
				FilledRegionType filledRegionType3 = element as FilledRegionType;
				if (filledRegionType2 == null)
				{
					filledRegionType = filledRegionType3;
				}
				if (filledRegionType3.Name.CompareTo("HYFilledRegionType") == 0)
				{
					filledRegionType2 = filledRegionType3;
					break;
				}
			}
			if (filledRegionType2 != null)
			{
				return filledRegionType2;
			}
			if (filledRegionType == null)
			{
				return null;
			}
			try
			{
				filledRegionType2 = (filledRegionType.Duplicate("HYFilledRegionType") as FilledRegionType);
				FillPatternElement solidPattern = this.GetSolidPattern("实体填充");
				filledRegionType2.FillPatternId = solidPattern.Id;
			}
			catch (Exception)
			{
				return null;
			}
			return filledRegionType2;
		}

		private FillPatternElement GetSolidPattern(string patternName)
		{
			foreach (Element element in new FilteredElementCollector(this.m_doc).OfClass(typeof(FillPatternElement)).ToElements())
			{
				FillPatternElement fillPatternElement = element as FillPatternElement;
				if (fillPatternElement != null && fillPatternElement.Name.CompareTo(patternName) == 0)
				{
					return fillPatternElement;
				}
			}
			return null;
		}

		private string DoubleToString(double dValue, string strFormat)
		{
			string text = dValue.ToString(strFormat);
			if (text.IndexOf(".") >= 0)
			{
				while (text.Last<char>() == '0')
				{
					text = text.Left(text.Length - 1);
				}
				text = Convert.ToDouble(text).ToString();
			}
			return text;
		}

		private bool IsTwoCurveGroupIntersect(List<Curve> lstCurve1, List<Curve> lstCurve2)
		{
			foreach (Curve curve in lstCurve1)
			{
				YJKCurve hycurve = new YJKCurve(curve);
				foreach (Curve otherCurve in lstCurve2)
				{
					if (hycurve.IntersectionPoint(otherCurve) != null)
					{
						return true;
					}
				}
			}
			return false;
		}

		private bool IsHasPoint(List<XYZ> lstPoint, XYZ ptNew)
		{
			using (List<XYZ>.Enumerator enumerator = lstPoint.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.IsAlmostEqualTo(ptNew, 0.005))
					{
						return true;
					}
				}
			}
			return false;
		}

		private bool IsHasReference(ReferenceArray aryOldRef, Reference refNew)
		{
			IEnumerator enumerator = aryOldRef.GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					if (((Reference)enumerator.Current).ElementId == refNew.ElementId)
					{
						return true;
					}
				}
			}
			return false;
		}

		private bool ReadXmlFillRegion(string strMaterial, ref string strMinFillRefion, ref string strMaxFillRegion)
		{
			string text = Product.DataLocation + "\\StairsSecFillPatternConfig.xml";
			if (!File.Exists(text))
			{
				return false;
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(text);
			XmlNode xmlNode = xmlDocument.SelectSingleNode("Root").SelectSingleNode(string.Format("MateriaData[@Name=\"{0}\"]", strMaterial));
			if (xmlNode == null)
			{
				return false;
			}
			XmlNodeList xmlNodeList = xmlNode.SelectNodes("OneScale");
			if (xmlNodeList.Count != 2)
			{
				return false;
			}
			foreach (object obj in xmlNodeList)
			{
				XmlElement xmlElement = ((XmlNode)obj) as XmlElement;
				if (xmlElement.GetAttribute("Scale") == "1.5")
				{
					strMaxFillRegion = xmlElement.GetAttribute("NameModify");
				}
				else
				{
					strMinFillRefion = xmlElement.GetAttribute("NameModify");
				}
			}
			return !string.IsNullOrEmpty(strMinFillRefion) && !string.IsNullOrEmpty(strMaxFillRegion);
		}

		private void SetElemColorByDimType(ElementId beSetElemId)
		{
			Parameter parameter = this.m_dimType.GetParameter(BuiltInParameter.LINE_COLOR);
			if (parameter != null)
			{
                Autodesk.Revit.DB.Color projectionLineColor = DrawingKit.IntToRGB(parameter.AsInteger());
				OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();
				overrideGraphicSettings.SetProjectionLineColor(projectionLineColor);
				this.m_doc.ActiveView.SetElementOverrides(beSetElemId, overrideGraphicSettings);
			}
		}

		private double GetMinDist(XYZ pt, List<XYZ> lstPt)
		{
			double num = 0.0;
			foreach (XYZ xyz in lstPt)
			{
				double num2 = pt.DistanceTo(xyz);
				if (num2 >= 0.001 && (num < 0.001 || num > num2))
				{
					num = num2;
				}
			}
			return num;
		}

		private double CalRampVertThick()
		{
			double floorThick = this.GetFloorThick(this.m_floorType);
			double result = floorThick;
			List<SegmentData> value = this.m_lstAllSegmentData.First<KeyValuePair<Level, List<SegmentData>>>().Value;
			for (int i = 0; i < value.Count; i++)
			{
				SegmentData segmentData = value[i];
				if (segmentData.VertArcRadius < 0.01)
				{
					double num = segmentData.Length();
					double num2 = AssistFunc.mmToFeet(segmentData.EndElevation - segmentData.StartElevation);
					result = Math.Sqrt(num * num + num2 * num2) * floorThick / num;
					break;
				}
			}
			return result;
		}

		private double GetFloorThick(FloorType floorType)
		{
			double result = AssistFunc.mmToFeet(200.0);
			Parameter parameter = floorType.GetParameter(BuiltInParameter.FLOOR_ATTR_DEFAULT_THICKNESS_PARAM);
			if (parameter != null && parameter.AsDouble() > 0.01)
			{
				result = parameter.AsDouble();
			}
			return result;
		}

        private static Autodesk.Revit.DB.Color IntToRGB(int nColor)
		{
			byte b = (byte)(255 & nColor);
			int num = 65280 & nColor;
			num >>= 8;
			int num2 = 16711680 & nColor;
			num2 >>= 16;
            return new Autodesk.Revit.DB.Color(b, (byte)num, (byte)num2);
		}

		private void GetFloorTypeLayer(FloorType floorType, ref CompoundStructureLayer finishLayer, ref CompoundStructureLayer structLayer)
		{
			IList<CompoundStructureLayer> layers = floorType.GetCompoundStructure().GetLayers();
			if (layers.Count < 1)
			{
				return;
			}
			if (layers.Count == 1)
			{
				structLayer = layers[0];
			}
			else if (layers.Count == 2)
			{
				finishLayer = layers[0];
				structLayer = layers[1];
			}
			else
			{
				finishLayer = null;
				foreach (CompoundStructureLayer compoundStructureLayer in layers)
				{
					if ((int)compoundStructureLayer.Function == 4 || (int)compoundStructureLayer.Function == 5)
					{
						finishLayer = compoundStructureLayer;
						break;
					}
				}
				if (finishLayer == null)
				{
					finishLayer = layers[0];
				}
				structLayer = null;
				foreach (CompoundStructureLayer compoundStructureLayer2 in layers)
				{
					if ((int)compoundStructureLayer2.Function == 1)
					{
						structLayer = compoundStructureLayer2;
						break;
					}
				}
				if (structLayer == null)
				{
					structLayer = layers[1];
				}
				if (finishLayer.LayerId == structLayer.LayerId)
				{
					finishLayer = layers[0];
					structLayer = layers[1];
				}
			}
			double floorThick = this.GetFloorThick(this.m_floorType);
			if (finishLayer == null)
			{
				structLayer.Width = floorThick;
				return;
			}
			structLayer.Width = floorThick - finishLayer.Width;
		}

		private const PenColor m_RampColor = PenColor.PC_Gray;

		private const PenColor m_TextColor = PenColor.PC_Black;

		private const PenColor m_ArrowColor = PenColor.PC_Black;

		private const PenColor m_NodeColor = PenColor.PC_Black;

		private UIApplication m_uiApp;

		private Application m_app;

		private UIDocument m_uiDoc;

		private Autodesk.Revit.DB.Document m_doc;

		private Dictionary<Level, List<SegmentData>> m_lstAllSegmentData;

		private List<ElementId> m_lstNewElemId;

		private DimensionType m_dimType;

		private TextNoteType m_textType;

		private FloorType m_floorType;

		private int m_nSlopeType;

		private List<ElementId> m_lstAxisId;

		private double m_dMinDist = AssistFunc.mmToFeet(1.0);

		public struct RichPoint
		{
			public RichPoint(XYZ point, Curve curve)
			{
				this.m_point = point;
				this.m_curves = new List<Curve>();
				this.m_curves.Add(curve);
			}

			public void AddCurve(Curve curve)
			{
				this.m_curves.Add(curve);
			}

			public XYZ m_point;

			public List<Curve> m_curves;
		}
	}
}
